var MainPage = {
	
	init: function() {
		// Scope change
		var _this = this;
	
		// Init all helper texts
		$('.with_default_text').each(function(index) {
			$(this).bind({
				// Helper Text
				focus: function(e) {
					if ($(this).val() == $(this).attr('def_text')) {
						$(this).val('');
						//$(this).css('font-style', 'normal');
					}
					return true;
				},
				blur: function(e) {
					if ($(this).val() == '') {
						$(this).val($(this).attr('def_text'));
						//$(this).css('font-style', 'italic');
					}
					return true;
				}
			});
		});
		$('.with_default_text').blur();
		
		// Share Init
		$('a.share-facebook').click(function () {
			_this.openCenteredWindow(this.href);
			return false;
		});
		$('a.share-it').click(function () {
			$(this).parent().next('li').toggle();
			$(this).parent().toggleClass('share-active');
		});
	},
	
	openCenteredWindow: function(url) {
		var parms = ',menubar=no,width=600,height=500,toolbar=no';
		var name = "facebook_share";
		var height = 500;
		var width = 600;
		var left = Math.floor( (screen.width - width) / 2);
		var top = Math.floor( (screen.height - height) / 2);
		
		var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width + parms;

		var win = window.open(url, name, winParms);
		win.window.focus();
		return win;
	},
	
	showMask: function(el){
		el = $(el)
		if(!el || el.mask_element) return;
		var element_loader = $('<div class="itc-mask"><div class="loading-indicator"></div></div>');
		if ($.browser.msie && $.browser.version < 7) {
			var w = el.offsetWidth;
			element_loader.css({
				'height':h+'px',
				'width':w+'px'
			});
		}
		if (el.css('position') != 'relative') {
			el.css('position', 'relative');
		}
		element_loader.appendTo(el);
		return true;
	},
	
	hideMask: function(el) {
		$('.itc-mask').remove();
	}
};

$(function() { MainPage.init(); });